********************************************************************************
*
* What do parents want? Parental spousal prefernces in China
* Date: September 2021
*	
* MAIN QSAMPY Preference estimation (section 4)
* 
* Stata version 15
* This do file: 
* Generate table 3 (summary statistics) 
* estimations 1, 2, 6, and 7; figure 3;
* At the end, also includes the stats needed to discuss the strictness of the acceptance sets (section 6.2)
*
* other do file 
* MAIN STUDENT Preferences estimation (for section 6.1)
* 
* other R scripts:
* MAIN Simulation (for section 5.2. and appendix)
* acceptance sets (section 6.2.)
* marriage distribution graphs
********************************************************************************

** working directory: folder where data is saved and where output will be saved
cd ""

set scheme s1mono
set more off
set matsize 800


***************************** summary statistics *******************************
********************** table 3 *************************************************
**** no output: copy and pasted
** ssc install sutex

use "summary_statistics_glp.dta", clear
sum respondent_* at_park search_female age subject*
sutex respondent_* at_park search_female age subject*, label

use "summary_statistics_glp_matched.dta", clear
sum respondent_* at_park choose_female age subject*
sutex respondent_* at_park choose_female age subject*, label

************************** PREFERENCE ESTIMATION  *******************************

use "meet_data_final.dta", clear

*** generate and label some additional variables
gen owns_real = (propert ==1 | property ==2 | property==3)
gen profilereal_owns_real = profilereal*owns_real 
label var  profilereal_owns_real "Subject: Owns real estate X Profile: Owns real estate"

gen age_cat = .
replace age_cat = 1 if profileage >= 16 & profileage <=25
replace age_cat = 2 if profileage > 25 & profileage <=30
replace age_cat = 3 if profileage > 30 & profileage <=35
replace age_cat = 4 if profileage > 35 & profileage <=40
replace age_cat = 5 if profileage > 40 & profileage <=45
replace age_cat = 6 if profileage > 45

label define age_cat 1 "Profile: Up to age 25" 2 "Profile: Age 26 to 30" 3 "Profile: Age 31 to 35" 4 "Profile: Age 36 to 40" ///
5 "Profile: Age 41 to 45" 6 "Profile: Over age 45"
label values age_cat age_cat


** use those who search on behalf of someone else
keep if search_who==1


********************************************************************************
********************** table 1 (tab1_agecat) ***********************************

logit meet i.profileedu han c.profloginc i.age_cat profilereal i.id_num ///
 if choose_female==1, cluster(id_num)
estpost margins, dydx(profileedu han profloginc age_cat profilereal)
est store A
estadd local hasrep "YES"
logit meet i.profileedu han c.profloginc i.age_cat profilereal i.id_num ///
 if choose_female==1 & high_edu==0, cluster(id_num)
estpost margins, dydx(profileedu han profloginc age_cat profilereal)
est store B
logit meet i.profileedu han c.profloginc i.age_cat profilereal  i.id_num ///
 if choose_female==1 & high_edu==1, cluster(id_num)
estpost margins, dydx(profileedu han profloginc age_cat profilereal)
est store C

		
logit meet i.profileedu han c.profloginc i.age_cat profilereal i.id_num ///
 if choose_female==0, cluster(id_num)
estpost margins, dydx(profileedu han profloginc age_cat profilereal)
			est store E
logit meet i.profileedu han c.profloginc i.age_cat profilereal i.id_num ///
 if choose_female==0 & high_edu==0, cluster(id_num)
estpost margins, dydx(profileedu han profloginc age_cat profilereal) 
			est store F
logit meet i.profileedu han c.profloginc i.age_cat profilereal i.id_num ///
 if choose_female==0 & high_edu==1, cluster(id_num)
estpost margins, dydx(profileedu han profloginc age_cat profilereal)
			est store G
	
esttab A B C  E F G  using tab1_agecat.tex, replace label nobaselevels interaction(" X ") se f noomit  b(%5.3f) ///
star( * 0.10 ** 0.05 *** 0.01) addnotes(Indvidual FE, YES)  mtitles


*** for comparison between high school and university degree (section 1.1)
logit meet ib2.profileedu han c.profloginc i.age_cat profilereal i.id_num ///
 if choose_female==0 & high_edu==1, cluster(id_num)
estpost margins, dydx(profileedu han profloginc age_cat profilereal) 

logit meet ib2.profileedu han c.profloginc i.age_cat profilereal i.id_num ///
 if choose_female==1 & high_edu==1, cluster(id_num)
estpost margins, dydx(profileedu han profloginc age_cat profilereal) 


*** for comparison between high school and graduate degree profiles for non-educated male subjects
logit meet ib2.profileedu han c.profloginc i.age_cat profilereal i.id_num ///
 if choose_female==0 & high_edu==0, cluster(id_num)
estpost margins, dydx(profileedu han profloginc age_cat profilereal) 

********************************************************************************
********************** table 2 (tab1_difference)********************************

logit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real i.id_num ///
 if choose_female==1, cluster(id_num)
estpost margins, dydx(edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal  profilereal_owns_real)
			est store A
logit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real i.id_num ///
 if choose_female==1 & high_edu==0, cluster(id_num)
estpost margins, dydx(edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real)
		est store B		
logit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real  i.id_num ///
 if choose_female==1 & high_edu==1, cluster(id_num)
estpost margins, dydx(edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real)
			est store C			
logit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_pos2  age_diff_neg age_diff_neg2 profilereal profilereal_owns_real  i.id_num ///
 if choose_female==1, cluster(id_num)
estpost margins, dydx(edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_pos2  age_diff_neg age_diff_neg2 profilereal profilereal_owns_real)
			est store D	
			
	
logit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real i.id_num ///
 if choose_female==0, cluster(id_num)
estpost margins, dydx(edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real)
			est store E
logit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real i.id_num ///
 if choose_female==0 & high_edu==0, cluster(id_num)
estpost margins, dydx(edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real) 
			est store F
logit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real i.id_num ///
 if choose_female==0 & high_edu==1, cluster(id_num)
estpost margins, dydx(edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real)
			est store G
logit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_pos2  age_diff_neg age_diff_neg2  profilereal profilereal_owns_real i.id_num ///
 if choose_female==0, cluster(id_num)
estpost margins, dydx(edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_pos2  age_diff_neg age_diff_neg2 profilereal profilereal_owns_real)
			est store H

*** 
esttab A B C D  E F G H using tab1_differences.tex, replace label nobaselevels interaction(" X ") se f noomit b(%5.3f)  ///
star(  * 0.10 ** 0.05 *** 0.01) 

************************ comparison of different estimation methods ************

************ table 6 (tab1_comparison) *****************************************
logit meet i.profileedu han c.profloginc i.age_cat profilereal i.id_num ///
 if choose_female==1, cluster(id_num)
estpost margins, dydx(profileedu han profloginc age_cat profilereal)
est store A
reg meet i.profileedu han c.profloginc i.age_cat profilereal i.id_num ///
 if choose_female==1, cluster(id_num)
est store B
logit meet i.profileedu han c.profloginc i.age_cat profilereal i.id_num ///
 if choose_female==1, cluster(id_num)
est store C
clogit meet i.profileedu han c.profloginc i.age_cat profilereal  ///
 if choose_female==1, group(id_num) cluster(id_num)
est store D

logit meet i.profileedu han c.profloginc i.age_cat profilereal i.id_num ///
 if choose_female==0, cluster(id_num)
estpost margins, dydx(profileedu han profloginc age_cat profilereal)
est store E
reg meet i.profileedu han c.profloginc i.age_cat profilereal i.id_num ///
 if choose_female==0, cluster(id_num)
est store F
logit meet i.profileedu han c.profloginc i.age_cat profilereal i.id_num ///
 if choose_female==0, cluster(id_num)
est store G
clogit meet i.profileedu han c.profloginc i.age_cat profilereal  ///
 if choose_female==0, group(id_num) cluster(id_num)
est store H

esttab A B C D  E F G H using tab1_comparison.tex, replace label nobaselevels interaction(" X ") se f noomit  ///
keep(*profileedu* han profloginc *age_cat* profilereal) b(%5.3f) ///
star( * 0.10 ** 0.05 *** 0.01) 


********************************************************************************
********************** table 7 (tab1_differences_comparison)********************

logit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real i.id_num ///
 if choose_female==1, cluster(id_num)
estpost margins, dydx(edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal  profilereal_owns_real)
			est store A			
reg meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real i.id_num ///
 if choose_female==1, cluster(id_num)
		est store B		
logit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real  i.id_num ///
 if choose_female==1, cluster(id_num)
			est store C			
clogit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real ///
 if choose_female==1, group(id_num) cluster(id_num)
			est store D	
			
	
logit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real i.id_num ///
 if choose_female==1, cluster(id_num)
estpost margins, dydx(edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal  profilereal_owns_real)
			est store E		
reg meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real i.id_num ///
 if choose_female==1, cluster(id_num)
		est store F		
logit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real  i.id_num ///
 if choose_female==1, cluster(id_num)
			est store G		
clogit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos  age_diff_neg profilereal profilereal_owns_real ///
 if choose_female==1, group(id_num) cluster(id_num)
			est store H	

		
*** 
esttab A B C D  E F G H using tab1_differences_comparison.tex, replace label nobaselevels interaction(" X ") se f noomit  ///
keep(edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_neg profilereal profilereal_owns_real) b(%5.3f) ///
star(  * 0.10 ** 0.05 *** 0.01) 


**** graphs \label{age_diffm} (men)
cd "C:\Users\raiber.e\Dropbox\China Marriage Search\Submissions\Economic Development and Cultural Change\figures"
replace age_diff_neg = -age_diff_neg	

logit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg age_diff_pos age_diff_pos2 ///
 age_diff_neg age_diff_neg2 profilereal profilereal_owns_real  i.id_num ///
 if choose_female==0, cluster(id_num)
			margins, at( age_diff_neg=(0(1)-10)  age_diff_pos=(0))
			marginsplot, ylabel(0(0.2)1)
graph export age_diff_neg_male.png, replace
			margins, at( age_diff_pos=(0(1)10)  age_diff_neg=(0))
			marginsplot, ylabel(0(0.2)1) 
graph export age_diff_pos_male.png, replace			

logit meet edu_diff_pos edu_diff_neg han income_diff_pos income_diff_neg ///
age_diff_pos age_diff_pos2 age_diff_neg age_diff_neg2  profilereal i.id_num ///
 if choose_female==1, cluster(id_num)
			margins, at( age_diff_neg=(0(1)-10)  age_diff_pos=(0))
			marginsplot, ylabel(0(0.2)1)
graph export age_diff_neg_female.png, replace
			margins, at( age_diff_pos=(0(1)10)  age_diff_neg=(0))
			marginsplot, ylabel(0(0.2)1)
graph export age_diff_pos_female.png, replace
		
replace age_diff_neg = -age_diff_neg	



*************** For discussion on strictness on the acceptance levels ****

**************************** acceptance sets: strictness
use "meet_data_final.dta", clear

set more off

*** main variables
** use those who search on behalf of someone else
keep if search_who==1


gen pref_educ_low_adapt =.
** less that psecondary
replace pref_educ_low_adapt = 0 if pref_educ_low <= 2 
** secondary
replace pref_educ_low_adapt = 1 if pref_educ_low == 3
** high school (any, inclduing college)
replace pref_educ_low_adapt = 2 if pref_educ_low <= 6 &  pref_educ_low > 3
** bachelor (any, inclduing college)
replace pref_educ_low_adapt = 3 if pref_educ_low ==7
** graduate
replace pref_educ_low_adapt = 4 if pref_educ_low ==8
** go limit
replace pref_educ_low_adapt = 0 if pref_educ_low == 96

gen pref_educ_high_adapt =.
** less that psecondary
replace pref_educ_high_adapt = 0 if pref_educ_high <= 2 
** secondary
replace pref_educ_high_adapt = 1 if pref_educ_high == 3
** high school (any, inclduing college)
replace pref_educ_high_adapt = 2 if  pref_educ_high  <= 6 &   pref_educ_high > 3
** bachelor (any, inclduing college)
replace pref_educ_high_adapt = 3 if pref_educ_high  ==7
** graduate
replace pref_educ_high_adapt = 4 if  pref_educ_high  ==8
** go limit
replace pref_educ_high_adapt = 4 if  pref_educ_high  == 96

gen pref_age_low_adapt = pref_age_low if pref_age_low <= 90
gen pref_age_high_adapt = pref_age_high if pref_age_high <= 90
*****
gen educ_below = (profileedu < pref_educ_low_adapt  & pref_educ_low_adapt!= .)
gen educ_above = (profileedu > pref_educ_high_adapt  & pref_educ_high_adapt!= .)
gen age_below = (profileage < pref_age_low_adapt  & pref_age_low_adapt!= .)
gen age_above = (profileage > pref_age_high_adapt  & pref_age_high_adapt!= .)
gen educ_below_accept = (profileedu < pref_educ_low_adapt & meet ==1 & pref_educ_low_adapt!= .)
gen educ_above_accept = (profileedu > pref_educ_high_adapt & meet ==1 & pref_educ_high_adapt!= .)
gen age_below_accept = (profileage< pref_age_low_adapt & meet ==1 & pref_age_low_adapt!= .)
gen age_above_accept = (profileage > pref_age_high_adapt & meet ==1 & pref_age_high_adapt!= .)



collapse (max) educ_below educ_above age_below age_above educ_below_accept educ_above_accept age_below_accept age_above_accept, by(Id)





